//
//  AppleAppDemoApp.swift
//  AppleAppDemo
//
//  Created by 刘忠华 on 2025/9/9.
//

import SwiftUI

@main
struct AppleAppDemoApp: App {
    init() {
        printPlatformInfo()
    }
    
    var body: some Scene {
        WindowGroup {
            SharedContentView()
        }
        #if os(macOS)
        .windowStyle(.automatic)
        .windowResizability(.contentSize)
        #endif
    }
    
    private func printPlatformInfo() {
        let platformName = getPlatformName()
        print("🚀 ========== \(platformName) 平台检测 ==========")
        print("📱 当前平台: \(PlatformDetector.current.displayName)")
        print("🔧 设备类型: \(getDeviceTypeDescription())")
        print("👆 输入方式: \(getInputMethodDescription())")
        print("📏 字体大小配置: \(PlatformConfig.fontSize(for: PlatformDetector.current, base: 16))")
        print("📐 间距配置: \(PlatformConfig.spacing(for: PlatformDetector.current, base: 16))")
        print("🎨 圆角配置: \(PlatformConfig.cornerRadius(for: PlatformDetector.current, base: 8))")
        print("✅ 支持触控: \(PlatformDetector.current.supportsTouch ? "是" : "否")")
        print("🖱️ 支持鼠标: \(PlatformDetector.current.supportsMouse ? "是" : "否")")
        print("📺 支持遥控器: \(PlatformDetector.current.supportsRemote ? "是" : "否")")
        print("🌍 =================================")
    }
    
    private func getPlatformName() -> String {
        #if os(iOS)
        #if targetEnvironment(macCatalyst)
        return "macOS"
        #else
        if UIDevice.current.userInterfaceIdiom == .pad {
            return "iPadOS"
        } else {
            return "iOS"
        }
        #endif
        #elseif os(macOS)
        return "macOS"
        #elseif os(tvOS)
        return "tvOS"
        #else
        return "Unknown"
        #endif
    }
    
    private func getDeviceTypeDescription() -> String {
        if PlatformDetector.current.isMobile {
            return "移动设备"
        } else if PlatformDetector.current.isDesktop {
            return "桌面设备"
        } else if PlatformDetector.current.isTV {
            return "电视设备"
        }
        return "未知设备"
    }
    
    private func getInputMethodDescription() -> String {
        var methods: [String] = []
        
        if PlatformDetector.current.supportsTouch {
            methods.append("触控")
        }
        if PlatformDetector.current.supportsMouse {
            methods.append("鼠标")
        }
        if PlatformDetector.current.supportsRemote {
            methods.append("遥控器")
        }
        
        return methods.isEmpty ? "无" : methods.joined(separator: "、")
    }
}
